home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / ovrsgr.zip / OVRSGR.C < prev    next >
C/C++ Source or Header  |  1986-11-06  |  21KB  |  1,018 lines

  1. /*********************************************************************
  2.  
  3. Name:        ovrsgr.c
  4. Version:    1.0
  5.  
  6.   COPYRIGHT (c) 1985 BY DIGITAL EQUIPMENT CORPORATION, MAYNARD MASS.
  7.              ALL RIGHTS RESERVED.
  8.  
  9. Permission to copy without fee all or part of this material is granted
  10. provided that copies are not made or distributed for direct commercial
  11. advantage, the Digital Equipment Corporation copyright notice appears,
  12. the  disclaimer  below appears, and notice is given that copying is by
  13. permission  of  Digital  Equipment  Corporation.   To  copy  otherwise
  14. requires a specific license.
  15.  
  16. DISCLAIMER:
  17.  
  18. The  information herein is subject to change without notice and should
  19. not be construed as a commitment by Digital Equipment Corporation.
  20.  
  21. Digital Equipment Corporation assumes no responsibility for the use or
  22. reliability of this software.  This  software  is  provided  "as  is,"
  23. without  any  warranty  of  any  kind,  express  or  implied.  Digital
  24. Equipment Corporation will not be liable in any event for any  damages
  25. including  any  loss  of  data, profit, or savings, claims against the
  26. user by any other party, or  any  other  incidental  or  consequential
  27. damages arising out of the use of, or inability to use, this software,
  28. even if Digital Equipment Corporation is advised of the possibility of
  29. such damage.
  30.  
  31. DEFECT REPORTING AND SUGGESTIONS:
  32.  
  33. Please send reports of defects or suggestions for improvement directly
  34. to the author:
  35.  
  36.     Brian Hetrick
  37.     Digital Equipment Corporation
  38.     110 Spit Brook Road  ZKO1-2/J10
  39.     Nashua NH  03062-2698
  40.  
  41. Do NOT file a Software Performance Report on this software,  call  the
  42. Telephone Support Center regarding this software, contact your Digital
  43. Field Office regarding this  software,  or  use  any  other  mechanism
  44. provided for Digital's supported and warranted software.
  45.  
  46.  
  47. FACILITY:
  48.  
  49.     General utility programs.
  50.  
  51. ABSTRACT:
  52.  
  53.     Converts a file encoded in eight-bit ASCII  with  limited  control
  54.     character  use  into  an  equivalent  file  using the "set graphic
  55.     rendition" escape sequences to indicate bolding and underlining.
  56.  
  57.     Applicable ANSI standards are X3.4 (7-bit ASCII), X3.64 (Addition-
  58.     al controls for use with  ASCII),  and  (proposed)  X3.4.2  (8-bit
  59.     ASCII).
  60.  
  61. ENVIRONMENT:
  62.  
  63.     CP/M-86/80, compiled with Mark Williams Co. MWC86.
  64.     MS-DOS, compiled with Computer Innovations Co. C86.
  65.     VAX/VMS, compiled with VAX C.
  66.  
  67. AUTHOR:    Brian Hetrick, CREATION DATE: 10 May 1985.
  68.  
  69. MODIFIED BY:
  70.  
  71.     Brian Hetrick, 10-May-85: Version 1.0
  72.   000 -    Original creation of module.
  73.  
  74.   1986/11/06 -- Rahul Dhesi -- For ANSI.SYS on Iclones:  (a) changed
  75.      blob to be rectangular graphics character;  (b) changed underlining
  76.      to be inverse video.  See "#ifdef ICLONE".
  77.  
  78. *********************************************************************/
  79.  
  80. /*
  81.  *  INCLUDE FILES:
  82.  */
  83.  
  84. #include <stdio.h>
  85.  
  86. /*
  87.  *  TABLE OF CONTENTS:
  88.  */
  89.  
  90. /*
  91.  *  MACROS:
  92.  */
  93.  
  94. #define    MAXLINLEN    512        /*  Maximum width of line   */
  95.  
  96. #define    FLG_SPAN    1        /*  Span whitespace         */
  97.  
  98. #define    ATR_BLOB    1        /*  Different char overprint*/
  99. #define    ATR_UNDR    2        /*  Underline overprint        */
  100. #define    ATR_BOLD    4        /*  Same char overprint        */
  101.  
  102. /*
  103.  *  The following character is device dependent.  It should  print  as
  104.  *  a  blob of some type.  It is used to indicate that several dissim-
  105.  *  ilar characters have been overprinted.  The sequence given invokes
  106.  *  the  G1  character set, prints a lowercase 'a', and returns to the
  107.  *  G0 character set.  On devices such as Digital's  VT1xx  and  VT2xx
  108.  *  terminals, where the G1 set has been set to the "special graphics"
  109.  *  character set, this prints a checkerboard pattern.  The  SCS  (set
  110.  *  character  set)  escape sequence to put the special graphics char-
  111.  *  acter set into G1 is <ESC>)0.
  112.  */
  113.  
  114. #ifdef ICLONE
  115. #define  CHR_BLOB "\xFE"      /* small rectangle */
  116. #else
  117. #define    CHR_BLOB    "\016a\017"    /*  Checkerboard        */
  118. #endif
  119.  
  120. /*
  121.  *  OWN STORAGE:
  122.  */
  123.  
  124. struct chr_pos
  125. {
  126.     char        cp_attr;
  127.     char        cp_char;
  128. };
  129.  
  130. static FILE
  131.     * outfile;
  132.  
  133. static int
  134.     flags,
  135.     hpos = 0,
  136.     indent;
  137.  
  138. static struct chr_pos
  139.     line_image [MAXLINLEN];
  140.  
  141. /*
  142.  *  EXTERNAL REFERENCES:
  143.  */
  144.  
  145. static change_attr (old_attr, new_attr)
  146.  
  147. int
  148.     old_attr,
  149.     new_attr;
  150.  
  151. /*********************************************************************
  152.  
  153. FUNCTIONAL DESCRIPTION:
  154.  
  155.     Minimally updates "set graphic rendition" attributes.
  156.  
  157.     The term "minimal" is used advisedly.  The VT100 series and clones
  158.     allow  only  clearing all attributes and setting particular attri-
  159.     butes, while the VT200 series additionally allows clearing partic-
  160.     ular attributes.  Also, the VT100 series and clones allow only the
  161.     7-bit ASCII representation of CSI.  For maximal  device  independ-
  162.     ence, the VT100 limitations are assumed.
  163.  
  164. FORMAL PARAMETERS:
  165.  
  166.     Old_attribute.rg.v - The set of graphic rendition attributes  cur-
  167.     rently in effect.
  168.     New_attributes.rg.v - The  set  of graphic rendition attributes to
  169.     be put into effect.
  170.  
  171. RETURN VALUE:
  172.  
  173.     None.
  174.  
  175. IMPLICIT INPUTS:
  176.  
  177.     outfile - The file to which the escape sequence is to be sent.
  178.  
  179. IMPLICIT OUTPUTS:
  180.  
  181.     None.
  182.  
  183. SIDE EFFECTS:
  184.  
  185.     Sends an escape sequence to the output file.
  186.  
  187. *********************************************************************/
  188.  
  189. {
  190.     int
  191.     first_code;
  192.  
  193.     if (old_attr != new_attr)
  194.     {
  195.     /*
  196.      *  Have to do something.  Start the escape sequence.
  197.      */
  198.  
  199.     putc ('\033', outfile);
  200.     putc ('[', outfile);
  201.  
  202.     /*
  203.      *  See if must reset attributes.
  204.      */
  205.  
  206.     if (old_attr & (~ new_attr))
  207.     {
  208.         putc ('0', outfile);
  209.         first_code = 0;
  210.         old_attr = 0;
  211.     }
  212.     else
  213.     {
  214.         first_code = 1;
  215.     }
  216.  
  217.     /*
  218.      *  Need only attributes to be added.
  219.      */
  220.  
  221.     new_attr &= ~ old_attr;
  222.  
  223.     /*
  224.      *  Do the attributes.
  225.      */
  226.  
  227.     if (new_attr & ATR_BOLD)
  228.     {
  229.         if (! first_code)
  230.         {
  231.         putc (';', outfile);
  232.         }
  233.         putc ('1', outfile);
  234.         first_code = 0;
  235.     }
  236.  
  237.     if (new_attr & ATR_UNDR)
  238.     {
  239.         if (! first_code)
  240.         {
  241.         putc (';', outfile);
  242.         }
  243. #ifdef ICLONE
  244.        putc ('7', outfile);
  245. #else
  246.         putc ('4', outfile);
  247. #endif
  248.     }
  249.  
  250.     /*
  251.      *  End the escape sequence.
  252.      */
  253.  
  254.     putc ('m', outfile);
  255.     }
  256. }
  257.  
  258. static outlin (eol)
  259.  
  260. char
  261.     eol;
  262.  
  263. /*********************************************************************
  264.  
  265. FUNCTIONAL DESCRIPTION:
  266.  
  267.     Creates a text line corresponding to the line_image array.
  268.  
  269. FORMAL PARAMETERS:
  270.  
  271.     eol.rc.v - The vertical movement character that ended the line.
  272.  
  273. RETURN VALUE:
  274.  
  275.     None.
  276.  
  277. IMPLICIT INPUTS:
  278.  
  279.     line_image - A description of the line to be created.
  280.     outfile - The pointer to the stream upon which the line is  to  be
  281.     created.
  282.  
  283. IMPLICIT OUTPUTS:
  284.  
  285.     None.
  286.  
  287. SIDE EFFECTS:
  288.  
  289.     Produces output upon outfile.
  290.  
  291. *********************************************************************/
  292.  
  293. {
  294.     int
  295.     column,
  296.     last_attr,
  297.     span_attr;
  298.  
  299.     struct chr_pos
  300.     * end_ptr,
  301.     * max_ptr,
  302.     * start_ptr;
  303.  
  304.     /*
  305.      *  Turn NULs into spaces and find line length.
  306.      */
  307.  
  308.     for (start_ptr = & line_image [0], max_ptr = & line_image [-1];
  309.          start_ptr < & line_image [MAXLINLEN];
  310.          start_ptr ++)
  311.     {
  312.         if (0 == start_ptr -> cp_char)
  313.         {
  314.         start_ptr -> cp_char = ' ';
  315.         if (0 != start_ptr -> cp_attr)
  316.         {
  317.         max_ptr = start_ptr;
  318.         }
  319.     }
  320.     else
  321.     {
  322.         /*
  323.          *  It is not a space.
  324.          */
  325.  
  326.         max_ptr = start_ptr;
  327.     }
  328.     }
  329.  
  330.     last_attr = 0;
  331.     if (max_ptr != & line_image [-1])
  332.     {
  333.     /*
  334.      *  If necessary, make attributes span  blanks.   Do  this  by
  335.      *  finding  characters surrounding spans of blanks, and ORing
  336.      *  the blank's attributes with the AND of the  attributes  of
  337.      *  the surrounding characters.
  338.      *
  339.      *  In the following, start_pos is  the  index  of  the  first
  340.      *  blank  to  treat, and start_ptr points at its line_image[]
  341.      *  entry;  end_pos is the index of the first character not to
  342.      *  treat, and end_ptr points at its line_image[] entry.  Note
  343.      *  that any init